/* 
 *  Copyright (c) 2011—2013 Panguso.com. All rights reserved. 
 *  File Name:  TreeFileHelper.java                                      
 *  File Contents Outline :  树文件持久化类
 *  File  Create Date:   2012年7月30日
 *  File Version#: Revision#: #1                  
 *  File  Latest Modify Date : 2013年1月16日
 *  File Author :  bachuan@panguso.com
 */
package storage.dbhelper;

import cn.edu.thu.log.web.service.PropertiesReaderServices;
import cn.edu.thu.log.web.service.impl.PropertiesReaderServicesImpl;
import java.util.List;
import org.apache.cassandra.thrift.KeySlice;
import storage.util.StorageManager;


public class TreeFileHelper {

    public void saveTreeFile(String fileName,String fileContent) {
         PropertiesReaderServices x1 = PropertiesReaderServicesImpl.instance();
         StorageManager sm = new StorageManager(x1.getProperties("db_keySpace"), x1.getProperties("db_columnFamily_treeFile"));
//        sm.open();
        sm.setRowKey(fileName);
        sm.put("content", fileContent);

    }
    public String selectTreeFile(String fileName){
                 PropertiesReaderServices x1 = PropertiesReaderServicesImpl.instance();
         StorageManager sm = new StorageManager(x1.getProperties("db_keySpace"), x1.getProperties("db_columnFamily_treeFile"));
         List<KeySlice> result =  sm.get("key",fileName);
         String content = "";
         if(result.size()>0){
             KeySlice ks = result.get(0);
             content = new String(ks.getColumns().get(0).getColumn().getValue());
         }
         return content;
    }
 
    public static void main(String[] args){
        TreeFileHelper ph = new TreeFileHelper();
        ph.saveTreeFile("123456.txt","8\n2\n3\n");
        String s = ph.selectTreeFile("123456.txt");
       System.out.println(s);
    }
}
